import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Audio
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Music
import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.InputListener
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton

fun main(args: Array<String>)
{
    LwjglApplication(MainPage(), config {
        width = 480
        height = 320
        useGL20 = true
        backgroundFPS = 30
        foregroundFPS = 120
        initialBackgroundColor = Color.GRAY
        resizable = false
        title = "AudioDemo"
    })
}

class MainPage : ApplicationAdapter()
{

    private lateinit var stage: Stage
    private lateinit var button: ImageButton
    private lateinit var sound: Sound
    private lateinit var music: Music

    override fun create()
    {
        stage = Stage()

        sound = Gdx.audio.newSound(Gdx.files.internal("pick.wav"))
        music = Gdx.audio.newMusic(Gdx.files.internal("success.mp3"))

        button = ImageButton(drawable("button_normal.png"), drawable("button_click.png"))
        button.setPosition(50f, 50f)
        button.setSize(50f, 50f)
        button.setOnClickListener {
            sound.play()
        }
        stage.addActor(button)


        music.isLooping = false
        music.play()
        
        Gdx.input.inputProcessor = stage
    }

    override fun render()
    {
        clear()
        stage.act()
        stage.draw()
    }
}